/**
 * 将token存入Storage
 */
const setToken = ({ token = "", refresh = "" }) => {
	if (token != "") {
    uni.setStorage({
      key: 'token',
      data: token,
      success: function (e) {
        // console.log('set token');
      }
    })
  }
  if (refresh != "") {
    uni.setStorage({
      key: 'refresh',
      data: refresh,
      success: function (e) {
        // console.log('set refresh');
      }
    })
  }
}

/**
 * 获取token
 */
const getToken = () => {
  let strToken = ""
  try {
    strToken = uni.getStorageSync('token');
  } catch (e) { }
  return strToken
}

const getRefresh = () => {
  let strRefresh = ""
  try {
    strRefresh = uni.getStorageSync('refresh');
    console.log('get refresh');
  } catch (e) { }
  return strRefresh
}

const removeToken = () => {
  uni.removeStorage({
    key: 'token',
    success(res) {
      console.log("移除token")
    }
  })
  uni.removeStorage({
    key: 'refresh',
    success(res) {
      // console.log("移除refresh")
    }
  })
}

export default {
  setToken: setToken,
  getToken: getToken,
  getRefresh: getRefresh,
  removeToken: removeToken
}